#include <iostream>
using namespace std;
#define int long long
int x,y;
signed main()
{
	int ans=0;
	cin>>x>>y;
	if(y>x)
	swap(x,y);
	while(x!=0&&y!=0)
	{
		int cnt=x/y;
		int z=min(x,y);
		ans+=z*4*cnt;
		if(z==x) y-=x*cnt;
		else if(z==y) x-=y*cnt;
		swap(x,y); 
	}
	cout<<ans<<endl;
	return 0;
}
